package com.test.multithread.lock.condition;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class waitNotify {
    Lock lock = new ReentrantLock();
    Condition condition = lock.newCondition();
    public void await(){
        try {
            lock.lock();
            System.out.println(Thread.currentThread().getName() + "准备进行等待");
            condition.await();
            System.out.println(Thread.currentThread().getName() + "结束等待");
            lock.unlock();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    public void signalAll(){
        lock.lock();
        System.out.println(Thread.currentThread().getName() + "准备通知");
        condition.signal();
        System.out.println(Thread.currentThread().getName() +  "通知完后在再释放锁");
        System.out.println(Thread.currentThread().getName() + "通知结束");
        lock.unlock();
    }
}

